In this course, we’ll learn research methods by actually working with data to conduct empirical analysis.
To do that we’ll use R, a free and open-source software environment for statistical computing and graphics. the graphical user interface R Studio.
Below are some steps to get you set up so that we can get started next class.
If you’re pressed for time here’s the short version of what you should do before next class.
rmarkdown)cmd + shift + k PC: crtl + shift + kSpecifically copy and paste the following into the console in R Studio and hit enter:
install.packages("devtools")
install.packages("remotes")
remotes::install_github("kosukeimai/qss-package", build_vignettes = TRUE)
remotes::install_github("rstudio/learnr")
remotes::install_github("rstudio-education/gradethis")
remotes::install_github("PaulTestaBrown/qsslearnr")
You’ll need to have the package rmarkdown installed for
remotes::install_github("kosukeimai/qss-package", build_vignettes = TRUE)
Using github PAT from envvar GITHUB_PAT
Skipping install of 'qss' from a github remote, the SHA1 (753787f2) has not changed since last install.
Use `force = TRUE` to force installation
To work, so make sure you open your first .Rmd file first (this will automatically prompt you to install the rmarkdown package)
If you have a question or somethings not working, don’t hesitate to ask. Please email me at paul_testa@brown.edu or come to my office at 111 Thayer St Rm 339.
R - Just click yes, on everything the installer asks
Download the desktop version of RStudio here: https://www.rstudio.com/products/rstudio/download/
Scroll down till you get to something like this
R Markdown is a file format that allows us to combine R code – which we use to do our statistical analysis – with Markdown – a lightweight markup language that can turn plain text into all sorts of formats (.pdf, .doc, .html)
rmarkdown and some packages rmarkdown needs. Please do sormarkdown packagermarkdown is intalled, R Studio should ask you what kind of file you want to make, choose html (the default) and fill in things like the title or author if you want.-Click the knit button in the Source/Text editor on the upper left and see what happens
On you’re machine, R turned your
FILENAME.Rmd (I named mine Test.Rmd) into FILNENAME.html.
Under the hood, it ran some software that ran your R code (stuff in the grey) and combined it with the markdown text (stuff in the white), to produce the final html file. If you click on that file, it will open in your web browser
devtools and remotes packagesThe version of R that you just downloaded is considered base R, which provides you with good but basic statistical computing and graphics powers.
To get the most out of R, you’ll need to install add-on packages, which are user-written to extend/expand your R capabilities.
Packages can live in one of two places:
install.packages("name_of_package", dependencies = TRUE).To download these packages, you first need to install the devtools and remotes packages.
install.packages("devtools")
install.packages("remotes")
Place your cursor in the console (lower left panel), and copy and paste each line of code above. After you’ve pasted a line, hit Enter/Return and R will execute (run) that line of code. So type:
install.packages(“devtools”)
Hit enter.
Then type
install.packages(“remotes”)
And hit enter again.
Each time, R will likely spit out some cryptic red text as installs the packages.
When it’s done, R will you should see a line with a single > in the console.
You should be able to see the newly installed packages by scrolling through or searching the Packages pane on the bottom left
Now we’ll use the intall_github() function from the remotes package, to install some packages we’ll use for this course.
Again, copy and paste each line of code into your console, and hit Enter/Return to run that code.
remotes::install_github("kosukeimai/qss-package", build_vignettes = TRUE)
remotes::install_github("rstudio/learnr")
remotes::install_github("rstudio-education/gradethis")
remotes::install_github("PaulTestaBrown/qsslearnr")
We’ll go over this during our next meeting so don’t worry if this doesn’t work
In particular, we’ll be using a version of Matthew Blackwell’s qsslearnr as problem sets for this course.
You can see the available problem sets by running the following code in your console:
learnr::run_tutorial(package = "qsslearnr")
And start a tutorial by running:
learnr::run_tutorial("00-intro", package = "qsslearnr")
To try and explain in words what this code is doing:
learnr::run_tutorial( Says use the run_tutorial() from the learnr package"00-intro" tells run_tutorial() to run the "00-intro" tutorialpackage = "qsslearnr" tells run_tutorial() to look for this tutorial in the qsslearnr package.If you run this code, you should see the following tutorial show up in the upper right panel:
You can also add a “Tutorial” panel to R Studio.
cmd + , on a Mac cntrl + , … No Shortcut for PC :(Pain Layout tab. In the upper right of the four pains, check the box next to TutorialThis is just personal perference, but while we’re changin some global options, I’d recommend
Finally, in the R General tab, I’d strongly recommend unchecking the box that says “Always save R History”
** Be sure to click OK** when you’re done updating these settings.
This guide has tried to help you get the software we’ll be using for this course set up. If everything’s gone as planned, you should have:
Bravo! Seriously, this stuff isn’t easy, and I really appreciate the time you put in. It will make our subsequent classes more smoothly.
Of course, everything rarely goes as planned. If you got an error or things don’t work out. Don’t worry. This literally always happens for a multitude of reasons. I promise we’ll take care of things in our next class.
##Additional References {-}
If you simply can’t wait to get started, you might explore some of the following
R:
R Markdown:
General: